// ==UserScript== // @name ChatGPT撑开页面宽度 // @namespace https://greasyfork.org/ // @version 1.1.3 // @description 将页面宽度展开 // @author OpenAI - ChatGPT // @match https://chat.openai.com/ // @match https://chat.openai.com/c/* // @match https://chat.openai.com/?* // @license AGPL-3.0-or-later // ==/UserScript== (function () { "use strict"; const newMaxWidth = "90rem"; const targetClassName = ".xl\\:max-w-3xl"; const targetClass = "flex flex-col text-sm dark:bg-gray-800"; const desiredMinWidth = 1280; const styleId = "await-max-width"; const btnId = "await-btn"; // const btnSvgId = "await-svg"; const btnShowTipId = "await-show-tip"; const textClass = "await-text"; function getById(id) { const btn = document.getElementById(id); if (!btn) { setTimeout(function () { return getById(); }, 1000); } return btn; } function styleCreate() { const style = document.createElement("style"); style.innerHTML = ` .${styleId} { max-width: ${newMaxWidth} !important; } .${btnId}{ right:2.8rem; } .${textClass}{ } `; document.head.appendChild(style); } function btnClickAdd() { //在 id为prompt-textarea的元素后面添加一个btnClick按钮 const promptTextarea = document.getElementById("prompt-textarea"); if (!promptTextarea) { setTimeout(function () { btnClickAdd(); }, 1000); return; } promptTextarea.insertAdjacentHTML( "afterend", ` ` ); } function removeStyle(el) { el.classList.remove(styleId); } function editStyle(el) { el.style.transition = "max-width 1s"; setTimeout(function () { el.style.transition = ""; }, 1000); el.classList.add(styleId); } function openSvg() { const btn = getById(btnId); //替换btn的svg btn.innerHTML = ""; btn.insertAdjacentHTML( "afterbegin", `撑开` // `撑开` ); // btn.insertAdjacentHTML( // "afterbegin", // `` // ); btn.addEventListener("click", function () { checkObserver(1); closeSvg(); }); } function closeSvg() { const btn = getById(btnId); btn.innerHTML = ""; btn.insertAdjacentHTML( "afterbegin", `还原` ); // btn.insertAdjacentHTML( // "afterbegin", // `` // ); btn.addEventListener("click", function () { checkObserver(2); openSvg(); }); } function showTip() { styleCreate(); const toggleButton = document.querySelector("nav"); if (!toggleButton) { setTimeout(function () { showTip(); }, 1000); return; } toggleButton.insertAdjacentHTML( "beforeend", `
如果页面宽度未展开,请重新点击此树结构导航栏
或者直接点击我
提示内容十秒后自动消失
` ); const btn = getById(btnShowTipId); btn.addEventListener("click", function () { run(); }); setTimeout(function () { btn.remove(); }, 10000); } function btnClick() { const toggleButton = document.querySelector("nav"); if (!toggleButton) { setTimeout(function () { btnClick(); }, 1000); return; } toggleButton.addEventListener("click", function () { setTimeout(function () { run(); btnClick(); }, 1000); }); } function checkForm() { var elementForm = document.querySelectorAll("form"); if (!elementForm || elementForm.length === 0) { setTimeout(function () { checkObserver(); }, 1000); return; } elementForm.forEach(function (element) { if (element.className.indexOf("xl:max-w-3xl") > -1) { editStyle(element); } }); } function checkObserver(type = 1) { var parentElement = document.getElementsByClassName(targetClass)[0]; if (!parentElement) { setTimeout(function () { checkObserver(type); }, 1000); return; } parentElement.querySelectorAll(targetClassName).forEach(function (flexDiv) { if (type === 1) { editStyle(flexDiv); } else { removeStyle(flexDiv); } }); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (addedNode) { var flexDivList = addedNode.querySelectorAll(targetClassName); flexDivList.forEach(function (flexDiv) { if (type === 1) { editStyle(flexDiv); } else { removeStyle(flexDiv); } }); }); }); }); var config = { childList: true, subtree: true }; observer.observe(parentElement, config); } function run() { checkForm(); checkObserver(); btnClickAdd(); closeSvg(); } window.addEventListener("resize", run); window.onload = function () { if (window.innerWidth < desiredMinWidth) { return; } showTip(); btnClick(); setTimeout(function () { run(); }, 2000); }; })();